package fr.umlv.jee.jawp.web;

import java.io.Serializable;
import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Service("appInfo")
@Component("appInfo")
public class AppInfo implements Serializable {
  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  private final String applicationName = "Jawp";
  private String date = getCurrentDate();
  private String search;
  
  public String getSearch() {
    return search;
  }
  
  public void setSearch(String search) {
    this.search = search;
  }
  
  public String getDate() {
    return date;
  }
  
  public AppInfo() {
  }

  public static String getCurrentDate() {
    Locale locale = Locale.getDefault();
    GregorianCalendar calendar = new GregorianCalendar(locale);
    calendar.setTime(new Date());

    String[] months = new DateFormatSymbols(Locale.ENGLISH).getMonths();
    String[] days = new DateFormatSymbols(Locale.ENGLISH).getWeekdays();
    
    String date = days[calendar.get(Calendar.DAY_OF_WEEK)] + " "
        + calendar.get(Calendar.DAY_OF_MONTH) + " "
        + months[calendar.get(Calendar.MONTH)] + " "
        + calendar.get(Calendar.YEAR);

    return date;
  }

  public String getApplicationName() {
    return applicationName;
  }

  public String login() {
    System.out.println("test ");
    return "buyer";
  }
}
